import { Component, OnInit } from '@angular/core';
import {NgForm} from '@angular/forms';
import {ActivatedRoute} from '@angular/router';
import {HttpService} from '../../service/http.service';

@Component({
  selector: 'app-wish',
  templateUrl: './wish.component.html',
  styleUrls: ['./wish.component.css']
})
export class WishComponent implements OnInit {

  commentName = '';
  commentAuthor = '';
  tips: string;

  constructor(private route: ActivatedRoute,
              private httpService: HttpService) {
  }

  ngOnInit() {
  }

  onSubmit(theForm: NgForm) {
    if (theForm['bookName'] == null || theForm['bookName'] === '') {
      this.tips = '书名不能为空';
      return;
    }
    this.httpService.postWish(1, this.commentName, this.commentAuthor).then(r => {
      if (r['code'] === 0) {
        alert('留言成功!');
        this.commentName = '';
        this.commentAuthor = '';
      } else {
        alert(r['msg']);
      }
    });
  }
}
